home *** CD-ROM | disk | FTP | other *** search
/ Amiga Magazin: Amiga-CD 1996 March / Amiga-CD 1996 #3.iso / pd-software / mui_3.1 / developer / oberon / txt / sticknote.mod < prev    next >
Text File  |  1996-01-19  |  10KB  |  300 lines

  1. (*
  2.  * VERY Incomplete.
  3.  *
  4.  * Only an Example for Using MuiBasics.PopupBegin() and
  5.  * MuiBasics.PopupEnd and Hooks.
  6.  *
  7.  *
  8.  *
  9.  *)
  10.  
  11.  
  12. MODULE  StickNote;
  13.  
  14. IMPORT
  15.   Mui,
  16.   mb := MuiBasics,
  17.   Exec,
  18.   u := Utility,
  19.   l := StickNoteLocale,
  20.   v := StickNoteVersion,
  21.   y := SYSTEM,
  22.   I := Intuition,
  23.   Strings,
  24.   Dos;
  25.  
  26.  
  27. CONST
  28.  id      = 8000;
  29.  idAbout = id+1;
  30.  
  31. CONST
  32.   idMainWin = y.VAL(LONGINT, 'MAIN' );
  33.  
  34. TYPE  s2 = ARRAY 2 OF Exec.STRPTR;
  35.       dumhook = PROCEDURE ( hook : u.HookPtr; object : Exec.APTR; message : Exec.APTR ) : LONGINT;
  36. CONST
  37.   cs = s2( y.ADR( "FooBar" ), NIL );
  38.  
  39. VAR window, app : Mui.Object;
  40.     btfirst, btnext, btprev, btlast, btok, btdel, btnew, btshow : Mui.Object;
  41.     sttitle, stnote, btpopuptitle : Mui.Object;
  42.  
  43.     cbshow : Mui.Object;
  44.  
  45.     dum : Mui.Object;
  46.     signals : LONGSET;
  47.     running : BOOLEAN;
  48.  
  49.     activateHook, pressedHook : mb.Hook;
  50.  
  51.   PROCEDURE KeyButton( num : LONGINT ): Mui.Object;
  52.     VAR pos : LONGINT;
  53.         s : ARRAY 64 OF CHAR;
  54.         key : CHAR;
  55.     BEGIN
  56.       COPY( l.GetString( num )^, s );
  57.       pos := Strings.Occurs( s, "_" );
  58.       IF pos = -1 THEN
  59.         key := "\o";
  60.       ELSE
  61.         Strings.Delete( s, pos, 1 );
  62.         key := u.ToLower( s[pos] );
  63.       END;
  64.  
  65.       RETURN mb.KeyButton( s, key );
  66.     END KeyButton;
  67.  
  68.   PROCEDURE KeyCheckMark( num : LONGINT; checked : Exec.LONGBOOL ): Mui.Object;
  69.     VAR pos : LONGINT;
  70.         s : ARRAY 64 OF CHAR;
  71.         key : CHAR;
  72.     BEGIN
  73.       COPY( l.GetString( num )^, s );
  74.       pos := Strings.Occurs( s, "_" );
  75.       IF pos = -1 THEN
  76.         key := "\o";
  77.       ELSE
  78.         Strings.Delete( s, pos, 1 );
  79.         key := u.ToLower( s[pos] );
  80.       END;
  81.  
  82.       mb.keyLabel1( s, key );
  83.       mb.Child; RETURN mb.KeyCheckMark( checked, key );
  84.     END KeyCheckMark;
  85.  
  86.   PROCEDURE KeyLabelString( num : LONGINT): Mui.Object;
  87.     VAR pos : LONGINT;
  88.         s : ARRAY 64 OF CHAR;
  89.         key : CHAR;
  90.     BEGIN
  91.       COPY( l.GetString( num )^, s );
  92.       pos := Strings.Occurs( s, "_" );
  93.       IF pos = -1 THEN
  94.         key := "\o";
  95.       ELSE
  96.         Strings.Delete( s, pos, 1 );
  97.         key := u.ToLower( s[pos] );
  98.       END;
  99.  
  100.         mb.keyLabel2( s, key );
  101.         mb.Child; mb.StringObject;
  102.                        mb.StringFrame;
  103.                        mb.TagItem( Mui.aControlChar, ORD( key ) );
  104.                   RETURN mb.End();
  105.     END KeyLabelString;
  106.  
  107.   PROCEDURE KeyLabel( num, what : LONGINT );
  108.     VAR pos : LONGINT;
  109.         s : ARRAY 64 OF CHAR;
  110.         key : CHAR;
  111.     BEGIN
  112.       COPY( l.GetString( num )^, s );
  113.       pos := Strings.Occurs( s, "_" );
  114.       IF pos = -1 THEN
  115.         key := "\o";
  116.       ELSE
  117.         Strings.Delete( s, pos, 1 );
  118.         key := u.ToLower( s[pos] );
  119.       END;
  120.       CASE what OF
  121.        | 0 : mb.keyLabel( s, key );
  122.        | 1 : mb.keyLabel1( s, key );
  123.        | 2 : mb.keyLabel2( s, key );
  124.       ELSE HALT (20) END;
  125.     END KeyLabel;
  126.  
  127.   PROCEDURE PopupString( num : LONGINT; hook : mb.Hook; img : LONGINT): Mui.Object;
  128.     VAR pos : LONGINT;
  129.         s : ARRAY 64 OF CHAR;
  130.         key : CHAR;
  131.         str : Mui.Object;
  132.     BEGIN
  133.       COPY( l.GetString( num )^, s );
  134.       pos := Strings.Occurs( s, "_" );
  135.       IF pos = -1 THEN
  136.          key := "\o";
  137.       ELSE;
  138.          key := u.ToLower( s[pos+1] );
  139.       END;
  140.       mb.PopupBegin;
  141.          mb.Child; mb.StringObject;
  142.                       mb.StringFrame;
  143.                       mb.TagItem( Mui.aControlChar, ORD ( key ) );
  144.                    str := mb.End();
  145.       mb.popupEnd( hook, img, str );
  146.       RETURN str;
  147.     END PopupString;
  148.  
  149.   PROCEDURE PressedObject( hook : mb.Hook; obj : Mui.Object ; args : mb.Args) : LONGINT;
  150.     BEGIN
  151.       Dos.PrintF(" Yeah! You pressed the Popup Object\n" );
  152.       RETURN 0;
  153.     END PressedObject;
  154.  
  155.   PROCEDURE CreateApplication();
  156.   (*------------------------------------------
  157.     :Input.
  158.     :Output.
  159.     :Semantic.  Erstellt das Application Objekt und alle
  160.     :Semantic.  dazugehörigen Fenster die zum bedienen das Programms gehören
  161.     :Note.      Es werden nicht die Fenster IN denen die Notizn stehen generiert.
  162.     :Update.    22-Aug-1993 [awn] - erstellt.
  163.   --------------------------------------------*)
  164.     BEGIN
  165.       mb.ApplicationObject( Mui.aApplicationTitle      , y.ADR(v.name),
  166.                             Mui.aApplicationVersion    , y.ADR(v.ver),
  167.                             Mui.aApplicationCopyright  , y.ADR("© 1993 BY Albert Weinert"),
  168.                             Mui.aApplicationAuthor     , y.ADR("Albert Weinert"),
  169.                             Mui.aApplicationDescription, l.GetString( l.msgDescription ),
  170.                             Mui.aApplicationBase       , y.ADR("STICKNOTE"),
  171.                             u.end );
  172.         mb.SubWindow; mb.WindowObject( Mui.aWindowTitle, y.ADR( v.nameVer ),
  173.                                        Mui.aWindowID   , idMainWin,
  174.                                        u.end );
  175.                         mb.WindowContents; mb.VGroup;
  176.                                               mb.Child; mb.ColGroup( 2 );
  177.                                                           mb.GroupFrameT( l.GetString( l.frameNotes )^ );
  178.  
  179.                                                               mb.Child; KeyLabel( l.gadTitle, 2 );
  180.                                                               mb.Child; mb.HGroup;
  181.                                                                           pressedHook:=mb.MakeHook ( PressedObject );
  182.                                                                           mb.Child; sttitle := PopupString( l.gadTitle, pressedHook, Mui.iPopUp );
  183.                                                                           btpopuptitle := mb.GetHookObject( pressedHook );
  184.                                                                           mb.Child; cbshow := KeyCheckMark( l.gadShow, Exec.true );
  185.                                                                         mb.end;
  186.  
  187.                                                           mb.Child; stnote := KeyLabelString( l.gadContent );
  188.                                                         mb.end;
  189.                                               mb.Child; mb.VSpace( 2 );
  190.                                               mb.Child; mb.ColGroup( 4 );
  191.                                                           mb.TagItem( Mui.aGroupSameSize, Exec.true );
  192.                                                           mb.Child; btfirst := KeyButton( l.gadFirst);
  193.                                                           mb.Child; btprev  := KeyButton( l.gadPrev );
  194.                                                           mb.Child; btnext  := KeyButton( l.gadNext );
  195.                                                           mb.Child; btlast  := KeyButton( l.gadLast );
  196.                                                           mb.Child; btok    := KeyButton( l.gadOK );
  197.                                                           mb.Child; btnew   := KeyButton( l.gadNew );
  198.                                                           mb.Child; btdel   := KeyButton( l.gadRemove );
  199.                                                           mb.Child; btshow  := KeyButton( l.gadShowNotes );
  200.                                                         mb.end;
  201.                                           mb.end;
  202.                       window := mb.End();
  203.         IF window = NIL THEN
  204.           Dos.PrintF("Failed to create Window\n");
  205.           HALT( 20 );
  206.         END;
  207.  
  208.       app := mb.End();
  209.  
  210.       IF app = NIL THEN
  211.         Dos.PrintF("Failed to create Application\n");
  212.         Mui.DisposeObject( window ); window := NIL;
  213.         HALT(20);
  214.       END;
  215.     END CreateApplication;
  216.  
  217.     TYPE  ObjectArg = STRUCT( d : mb.ArgsDesc );
  218.               obj : Mui.Object;
  219.           END;
  220.  
  221.   PROCEDURE ActivateObject( hook : mb.Hook; obj : Mui.Object ; args : mb.Args) : LONGINT;
  222.   (*------------------------------------------
  223.     :Input.     hook : Hook; obj : Object auf welches der Hook ausgeführt wurde
  224.     :Input.     par : Parameter
  225.     :Output.
  226.     :Semantic.  Aktiviert das Object welches zuletzt aktiv war (z.B. String)
  227.     :Note.      Wenn keins Aktiviert war, dann wird das Aktiviert was man
  228.     :Note.      beim DOMethod-Aufruf übergeben hat.
  229.     :Update.    22-Aug-1993 [awn] - erstellt.
  230.   --------------------------------------------*)
  231.   (* $StackChk- *)
  232.  
  233.     VAR actObj : Mui.Object;
  234.  
  235.     BEGIN
  236.       mb.Get( obj, Mui.aWindowActiveObject, actObj );
  237.  
  238.       IF y.VAL(LONGINT, actObj) = Mui.vWindowActiveObjectNone THEN
  239.         mb.Set( obj, Mui.aWindowActiveObject, args(ObjectArg).obj );
  240.       ELSIF actObj # args(ObjectArg).obj THEN
  241.           mb.Set( obj, Mui.aWindowActiveObject, actObj );
  242.       END;
  243.       RETURN 0
  244.     END ActivateObject;
  245.  
  246.  
  247. BEGIN
  248.   l.OpenCatalog( NIL, "" );
  249.   CreateApplication;
  250.   activateHook := mb.MakeHook( ActivateObject );
  251.  
  252. (* *)
  253.   Mui.DoMethod( window, Mui.mWindowSetCycleChain,
  254.                 sttitle, btpopuptitle, stnote, cbshow,
  255.                 btfirst, btprev, btnext, btlast, btok, btnew, btdel, btshow, NIL );
  256.  
  257. (* Aktivieren des CloseGadgets, so das die entsprechende ID gesendet wird *);
  258.  
  259.   Mui.DoMethod( window, Mui.mNotify, Mui.aWindowCloseRequest, Exec.true,
  260.                 app, 2, Mui.mApplicationReturnID, Mui.vApplicationReturnIDQuit );
  261.  
  262.  
  263.   Mui.DoMethod( sttitle, Mui.mNotify, Mui.aStringAcknowledge, Mui.vEveryTime,
  264.                 window , 3, Mui.mSet, Mui.aWindowActiveObject, stnote );
  265.  
  266. (* Installiere den Hook der wenn das Fenster aktiviert wird, das letze
  267.    aktive Gadget aktiviert wenn keins aktiv war, dann soll das
  268.    Popup Gadget aktiviert werden *)
  269.  
  270.  
  271.   IF activateHook # NIL THEN
  272.     Mui.DoMethod( window, Mui.mNotify, Mui.aWindowActivate, Exec.true,
  273.                   window, 3, Mui.mCallHook, activateHook, btpopuptitle );
  274.   END;
  275.  
  276. (* Öffnen das Hauptfenster *)
  277.  
  278.   mb.Set( window, Mui.aWindowOpen, Exec.true );
  279.  
  280.   running := TRUE ;
  281.   WHILE running DO
  282.     CASE Mui.DOMethod( app, Mui.mApplicationInput, y.ADR(signals), u.end ) OF
  283.       | Mui.vApplicationReturnIDQuit :
  284.           running := FALSE;
  285.     ELSE END;
  286.     IF (running) & (signals # LONGSET{}) THEN y.SETREG( 0, Exec.Wait(signals) ) END;
  287.   END;
  288.  
  289.   mb.Set(window, Mui.aWindowOpen, Exec.false );
  290.  
  291. CLOSE
  292.   IF app # NIL THEN
  293.     Mui.DisposeObject( app );
  294.   ELSE
  295.     IF window # NIL THEN
  296.       Mui.DisposeObject( window );
  297.     END;
  298.   END;
  299. END StickNote.
  300.